#include <allegro5\allegro.h>
#include <allegro5\allegro_primitives.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_audio.h>
#include "sw_game_map.h"
#include "sw_game_state_main.h"
#include "sw_sound_manager.h"
#include "globals.h"

#include "sw_sprite_shizzle.h"

sw_sprite_shizzle::sw_sprite_shizzle(int x, int y) : sw_sprite(0x0) {
	bitmaps = new ALLEGRO_BITMAP*[2];
	bitmaps[0] = al_load_bitmap("images/sprite_main.png");
	bitmaps[1] = al_load_bitmap("images/sprite_main1.png");
	al_convert_mask_to_alpha(bitmaps[0], al_map_rgb(255, 0, 255));
	al_convert_mask_to_alpha(bitmaps[1], al_map_rgb(255, 0, 255));

	onground = false;
	frame_count = 0;
	direction = true;
	attacking = false;
}

sw_sprite_shizzle::~sw_sprite_shizzle() {
	al_destroy_bitmap(bitmaps[0]);
	al_destroy_bitmap(bitmaps[1]);
	delete[] bitmaps;
}

void sw_sprite_shizzle::compute_time_step() {

	frame_count = (frame_count+1) % 10;

	//if (global_input_manager->pressed(ALLEGRO_KEY_LEFT)) {
	//	direction = false;
	//	set_force_x(get_force_x()-50);
	//}
	//if (global_input_manager->pressed(ALLEGRO_KEY_RIGHT)) {
	//	direction = true;
	//	set_force_x(get_force_x()+50);
	//}
	//if (global_input_manager->pressed(ALLEGRO_KEY_UP)) {
	//	set_force_y(get_force_y()-50);
	//}
	//if (global_input_manager->pressed(ALLEGRO_KEY_DOWN)) {
	//	set_force_y(get_force_y()+50);
	//}
	
	if (global_input_manager->pressed(ALLEGRO_KEY_A)) {
		attacking = true;
	} else {
		attacking = false;
	}
	sw_sprite::compute_time_step();


}

ALLEGRO_BITMAP* sw_sprite_shizzle::get_bitmap() {
	return bitmaps[frame_count/5];
	//al_draw_bitmap(bitmaps[frame_count/5], top_left_x, top_left_y, 0);
	//if (attacking) {
	//	int tipx = direction ? top_left_x+width*3/2 : top_left_x-width;
	//	al_draw_line(top_left_x+width/2, top_left_y+height/2, tipx, top_left_y+height/2, al_map_rgb(0, 0, 255), 2);
	//}
	//al_draw_filled_rectangle(top_left_x, top_left_y, top_left_x+width, top_left_y+height, al_map_rgb(0, 0, 255));
}

void sw_sprite_shizzle::set_on_ground(bool g) {
	onground = g;
}